package demo1;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
public class Training {
    public static void main1(String[] args) {
        HashSet<String> set = new HashSet<>();
        int[] arr = new int[3];
        int count = 0;
        for (int i = 1; i <= 1999; i++) {
            if(!cheak(i)) {
                continue;
            }
            for (int j = 1; j <= 1999-i && j!=i; j++) {
                if(!cheak(j)) {
                    continue;
                }
                int k = 2019 - i - j;
                if(k>0 && k!=i && k!=j) {
                    arr[0] = i;
                    arr[1] = j;
                    arr[2] = k;
                    Arrays.sort(arr);
                    if(set.add(Arrays.toString(arr))) {
                        count++;
                    }
                }

            }
        }
    }

    private static boolean cheak(int n) {
        while(n>0) {
            if(n%10==2 || n%10==4) {
                return false;
            }
            n /= 10;
        }
        return true;
    }

    //数的分解
    public static void main2(String[] args) {
        int count = 0;
        for (int i = 1; i <= 2017; i++) {
            if(name(i)==false) {
                continue;
            }
            for (int j = 1; j <= 2017; j++) {
                if(j==i || name(j)==false) {
                    continue;
                }
                for (int k = 1; k <= 2017; k++) {
                    if(k==i || k==j || name(k)==false) {
                        continue;
                    }
                    if(k+j+i==2019) {
                        System.out.println("i="+i+"j="+j+"k="+k);
                        count++;
                    }
                }
            }
        }
        System.out.println(count/6);
    }

    private static boolean name(int n) {
        while(n>0) {
            if(n%10==2 || n%10==4) {
                return false;
            }
            n /= 10;
        }
        return true;
    }

    //特殊的数和
    public static void main3(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long sum = 0;
        for (int i = 1; i <= n; i++) {
            if(cheak2(i)) {
                sum += i;
            }
        }
        System.out.println(sum);
    }

    private static boolean cheak2(int n) {
        while(n>0) {
            if(n%10==0 || n%10==1 || n%10==2 || n%10==9) {
                return true;
            }
            n /= 10;
        }
        return false;
    }

    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int K = scanner.nextInt();
        Integer[] nums1 = new Integer[n];
        int[] nums2 = new int[n];
        for (int i = 0; i < n; i++) {
            nums1[i] = scanner.nextInt();
        }
        Arrays.sort(nums1,(i,j)->{
            return j-i;
        });
        for (int i = 0; i < n; i++) {
            nums2[i] = nums1[i]%3;
        }

    }

    //回文日期 （待修改）
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String day1 = scanner.next();
        String day2 = scanner.next();
        char[] a = day1.toCharArray();
        char[] b = day2.toCharArray();
        int year1 = Integer.valueOf(new String(a.copyValueOf(a, 0, 4)));
        int year2 = Integer.valueOf(new String(day2.copyValueOf(day2, 0, 4)));
        int month1 = Integer.valueOf(new String(day1.copyValueOf(day1, 4, 2)));
        int month2 = Integer.valueOf(new String(day2.copyValueOf(day2, 4, 2)));
        int num1 = Integer.valueOf(new String(day1.copyValueOf(day1, 6, 2)));
        int num2 = Integer.valueOf(new String(day2.copyValueOf(day2, 6, 2)));

        int count = 0;
        for (int i = year1; i <= year2; i++) {
            int[] days = {0,31,28,31,30,31,30,31,30,31,30,31};
            int j = 1;
            if(i==year1) {
                j = month1;
            }
            if((i%4==0 && i%100!=0) || i%400==0) {
                days[2] = 29;
            }
            for ( ; j <= 12; j++) {
                if(i==year2 && j>month2) {
                    break;
                }
                int k = 1;
                if(i==year1 && j==month1) {
                    k = num1;
                }
                for ( ; k <= days[j]; k++) {
                    if(i==year2 && j==month2 && k>num2) {
                        break;
                    }
                    String str = i+""+j+""+k;
                    if(cheak3(str)==true) {
                        count++;
                    }
                }
            }
        }
        System.out.println(count);
    }

    private static boolean cheak3(String str) {
        int left = 0;
        int right = 7;
        while(left<right) {
            if(str.charAt(left++)!=str.charAt(right--)) {
                return false;
            }
        }
        return true;
    }

    public static void main5(String[] args) {
        String str = "liandjlf";
        String monthString = str.charAt(4)+""+str.charAt(5);
    }
}
